/**
 * 
 */
package com.coder520.sync_learning.demo;

import java.util.concurrent.TimeUnit;

/**
 * @author zhaoyibo
 *
 */
public class ThreadGroupDaemon {
	public static void main(String[] args) throws InterruptedException {
		//如果设置了一个group为守护线程组，那么在没有活动线程的时候，这个group会被自动destroy，没有设置守护的则是相反的
		ThreadGroup group1=new ThreadGroup("group1");
		
		new Thread( group1, () -> {
			try {
				TimeUnit.SECONDS.sleep(1);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		},"group1-thread1").start();
		
		
		ThreadGroup group2=new ThreadGroup("group2");
		
		new Thread( group2, () -> {
			try {
				TimeUnit.SECONDS.sleep(1);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		},"group2-thread2").start();
		
		//设置守护线程
		group2.setDaemon(true);
		
		TimeUnit.SECONDS.sleep(3);
		
		System.out.println(group1.isDestroyed());
		System.out.println(group2.isDestroyed());
	}
}
